﻿//列表视图
NotesApp.views.NotesListView = Ext.extend(Ext.Panel, {
    notesStore: Ext.emptyFn,//Ext的空函数
    notesList: Ext.emptyFn,//Ext的空函数
    layout: 'fit',
    initComponent: function () {
        this.newButton = new Ext.Button({//新建按钮
            text: 'New',
            ui: 'action',
            handler: this.onNewNote,
            scope: this
        });
        this.topToolbar = new Ext.Toolbar({//工具条，放置新建按钮
            title: 'My Notes',
            items: [
                { xtype: 'spacer' },
                this.newButton
            ]
        });
        this.dockedItems = [this.topToolbar];//列表视图顶部绑定工具条
        this.notesList = new Ext.List({//新建一个Ext的list从notesStore存储中取数据显示
            store: this.notesStore,
            grouped: true,//进行分组，按照notesStore存储的分组规则进行分组
            emptyText: '<div style="margin:5px;">No notes cached.</div>',//空数据显示
            onItemDisclosure: true,//添加点击查看按钮
            itemTpl: '<div class="list-item-title">{title}</div>' +
                            '<div class="list-item-narrative">{narrative}</div>'
        });
        this.notesList.on('disclose', function (record, index, evt) {//绑定点击查看事件
            this.onEditNote(record, index);
        }, this),
        this.items = [this.notesList];
        NotesApp.views.NotesListView.superclass.initComponent.call(this);
    },
    onNewNote: function () {//点击新建按钮, 调用新建action
        Ext.dispatch({
            controller: NotesApp.controllers.notesController,
            action: 'newnote'
        });
    },
    onEditNote: function (record, index) {//点击每条记录, 调用记录编辑页面跳转action
        Ext.dispatch({
            controller: NotesApp.controllers.notesController,
            action: 'editnote',
            note: record
        });
    },
    refreshList: function () {//列表刷新方法
        this.notesList.refresh();
    }
});